<?php
function logCmd($view){
    $log=$view;
    if(is_array($view)){
        $log = print_r($view,true);
    }
    if(is_object($view)){
         $log = print_r($view,true);
    }
    

   
    echo "\n".date("Y-m-d H:i:s")." ".MODULE_NAME." ".ACTION_NAME." : ".$log."\n";
}

function CmdExec($cmd){
    passthru("D:\Work\Nginx_Php\php-5.3\php.exe -c D:\Work\Nginx_Php\php-5.3\php.ini index.php " .$cmd);
}

function pickImg(){
    
}

function get_Url_File($url){
    $CURL = curl_init ( $url );
    curl_setopt ( $CURL, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $CURL, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" );
    $FILEDATA = curl_exec ( $CURL );
    curl_close ( $CURL );
    return $FILEDATA;
}

function is_utf8($word)
{
    if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function toutf($text){
    if(is_utf8($text)){
        $text = u2b($text);
    }
   return $text;        
}



function u2b($text){
   return iconv("UTF-8", "gb2312", $text);
}

function wfile($file, $str, $mode = 'w') {
    $oldmask = @umask ( 0 );
    $fp = @fopen ( $file, $mode );
    @flock ( $fp, 3 );
    if (! $fp) {
        Return false;
    } else {
        @fwrite ( $fp, $str );
        @fclose ( $fp );
        @umask ( $oldmask );
        Return true;
    }
}

function get_domain($url)  {  
    $pattern = "/[/w-]+/.(com|net|org|gov|biz|com.tw|com.hk|com.ru|net.tw|net.hk|net.ru|info|cn|com.cn|net.cn|org.cn|gov.cn|mobi|name|sh|ac|la|travel|tm|us|cc|tv|jobs|asia|hn|lc|hk|bz|com.hk|ws|tel|io|tw|ac.cn|bj.cn|sh.cn|tj.cn|cq.cn|he.cn|sx.cn|nm.cn|ln.cn|jl.cn|hl.cn|js.cn|zj.cn|ah.cn|fj.cn|jx.cn|sd.cn|ha.cn|hb.cn|hn.cn|gd.cn|gx.cn|hi.cn|sc.cn|gz.cn|yn.cn|xz.cn|sn.cn|gs.cn|qh.cn|nx.cn|xj.cn|tw.cn|hk.cn|mo.cn|org.hk|is|edu|mil|au|jp|int|kr|de|vc|ag|in|me|edu.cn|co.kr|gd|vg|co.uk|be|sg|it|ro|com.mo)(/.(cn|hk))*/";  
    preg_match($pattern, $url, $matches);  
    if(count($matches) > 0)  { 
        return $matches[0];  
    }else{  
        $rs = parse_url($url); $main_url = $rs["host"];  
        if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)){  
            return $main_url;  
        }else{  
            $arr = explode(".",$main_url);  
            $count=count($arr);  
            $endArr = array("com","net","org");//com.cn net.cn 等情况  
            if (in_array($arr[$count-2],$endArr)){  
                $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];  
            }else{  
                $domain = $arr[$count-2].".".$arr[$count-1];  
            }  
          return $domain;  
        }  
    }  
} 